Repository navigation
Conversation
…pxHost The socket transport that follows needs the same dial, filter, session tracking and listener behaviour as RlpxHost. These move unchanged into internal types both hosts can use: - RlpxDialPolicy: the recent-IP filter with privileged IPs, and dialing a node's endpoint, then the other address family its verified ENR advertises - RlpxSessionTracker: the session events, the activity observer, marking a session disconnected a second after its connection closes, and at shutdown - RlpxListener: the fallback bind and the dual-mode listener socket - RlpxErrorHandler: the logging and disconnect policy for an error in the communication with a peer, from ZeroNettyP2PHandler.ExceptionCaught
…Pipelines Network.RlpxTransport (hidden, DotNetty by default) selects SocketRlpxHost, which runs RLPx sessions without DotNetty. It shares the dial, filter and session policy with RlpxHost, and the frame codec with the DotNetty handlers. Each connection runs three loops. A receive loop fills a pipe from the socket, waiting for data before it rents a buffer. A frame loop reads the pipe: the handshake, then frames, which it authenticates, decrypts block by block into a rented buffer and merges into packets. A send loop encodes the queued packets in batches and writes them to the socket. Each direction has its own cipher and MAC instances. Received packets are handled on ProcessingThreadCount dedicated threads, each connection pinned to one, with one FIFO per thread, as on DotNetty's executor group: the size limit, Snappy, ReceiveMessage and the error handling, in the order the frame loop queued them. A packet's queue position, Snappy mode and writability charge are fixed when it is queued, so a Hello queued before Snappy is enabled stays framed. The connection is the one owner of writability, with DotNetty's watermarks.
A connection runs on an in-memory socket against a scripted peer that holds the paired secrets, with a session that records what it is given and a pool that tracks every rental. The tests cover frames split at any offset, chunks and Snappy, failed MACs and merger errors for ordinary and privileged peers, ordering against a reset and against an error raised by a packet, the end of the stream mid-packet, the read and handshake timeouts, leases kept after shutdown, ordered sends from many threads, packets larger than the batch, short sends, the handshake without simulated latency, the encoding mode fixed at admission, and the watermarks, checked against DotNetty's channel. The host tests cover the listener, the inbound filter, refused, cancelled and pending dials, and shutdown, also through the node's service stopper. The connection takes an optional pool, a read timeout and a hook before decoding, for these tests; its writability moves into OutboundBytes. The handshake messages skip the simulated latency, as DotNetty writes them without PacketSender, and the MAC processors are disposed when the connection's loops end. An accept error other than a reset pauses the accept loop briefly.
…cket transport A peer's Hello and its first compressed packet can arrive in one read. The new test holds the processing thread until both are queued, then enables Snappy while handling the Hello, as P2PProtocolHandler does, and checks the second packet is decompressed. Deciding Snappy when the frame loop queues a packet instead fails it. The scripted peer now RLP-encodes packet type 0. SocketRlpxRoundTripBenchmarks runs RlpxRoundTripBenchmarks with both nodes on the socket transport; a separate class keeps the DotNetty rows' names, so they still compare with master's. SocketRlpxConnectionBenchmarks measures a connection on an in-memory stream, receiving frames and sending bursts, whole or split into small reads and sends; the peer encodes into a reused buffer and drains without decoding, so the allocations are the connection's.
Tests for the handshake size limit at 65535 bytes with its prefix, a handshake that completes while its ACK is still being sent, traffic in both directions at once, a delayed packet charged when queued, a partly sent packet charged until its last byte is sent, the dial deadline when ConnectTimeoutMs is zero, and the ENR alternate dialed after a refused primary, which now runs on both hosts. SocketRlpxHost.Shutdown returns the first call's task to every caller, so a second caller also waits for the shutdown to finish.
|
Claude finished @rubo's task in 3m 24s —— View job Review of PR #16473: RLPx transport on sockets and System.IO.Pipelines
Summary: This is careful work. The transport stays behind a hidden flag, DotNetty remains the default, and the refactor of Medium
Low
Checked, nothing to report
Mergeable: not yet. Item 1 is Medium and hasn't been acknowledged. |
Stateless guest cost
Variable cost by bucket, summed over shared blocks (excludes BASE)
Compared against |
…behind A socket connection queued every decoded packet for its processing thread without limit, so a slow handler let a peer pin unbounded memory. The frame loop now pauses at 16 MB of received packets not yet handled; the pipe then fills and TCP slows the peer. A pause doesn't count toward the read timeout.
…on fails A SessionCreated subscriber that threw escaped the accept loop and ended it, so the node stopped taking inbound peers, and the connection stayed tracked and open. The host now logs the failure and closes only that connection, as DotNetty closes only the channel whose handler failed. A dial that fails this way closes its connection the same way.
A shutdown that ran while Init was binding found no listener to close, and Init then published the socket and started an accept loop that exited at once, leaving the port bound. Init now publishes the listener under the host's lock only if no shutdown has started, and closes it otherwise.
…rrent sender Senders check writability before serializing, so several could pass the check before one of them crossed the high watermark, and all of them were queued. Admission now checks writability again under the send lock and drops the packet, returning 0 as for a packet refused up front. A packet dropped by a close still counts as sent, as on DotNetty.
…transport tests The Hello and Snappy test and the error ordering test slept 100 ms to let packets reach the processing thread's queue. They now wait for the connection's count of queued received bytes. The pending dial test is inconclusive rather than passing when the network refuses its address at once.
…ocket connection Only a failing session activation was caught, so an exception elsewhere while setting up an inbound connection, such as in the inbound filter, still ended the accept loop. Setting up a connection now closes only that connection on any failure.
…ore the frame loop waits
|
Claude finished @rubo's task in 1m 14s —— View job Re-review of PR #16473: RLPx transport on sockets and System.IO.Pipelines
Summary: The Medium from the previous review is fixed. The commits since then are correct as far as I could tell. I found one new Low item and no Critical, High or Medium. I didn't build the code or run the tests; this is a read-only review. Previous findings
Low
Checked, nothing to report
Mergeable: yes. The only open Medium was fixed, and the open Lows are optional. |
|
|
||
| Metrics.OutgoingConnections++; | ||
| if (_logger.IsTrace) _logger.Trace($"|NetworkTrace| Initializing {session:hide} channel"); | ||
| StartSession(socket, connection, session); |
There was a problem hiding this comment.
Low: a dial whose session fails to activate still reports success.
When _sessions.Activate throws, StartSession now closes the connection and returns. It returns void, though, so TryConnect goes on to log OUT connected and return true. RlpxDialPolicy.ConnectAsync then treats the primary endpoint as connected and never tries the ENR alternate. This doesn't leak anything, and an outbound subscriber failing is unlikely. If you want the result to be accurate, StartSession could return bool and TryConnect could return false on failure. Optional.
Changes
Fifth of the PRs that make the RLPx stack independent of DotNetty, after #15775, #15874, #16103 and #16427. This one adds an RLPx transport on sockets and System.IO.Pipelines. The hidden
Network.RlpxTransportsetting selects it asSockets; DotNetty stays the default.System.IO.Pipelinesships with .NET, so nothing new is referenced.RlpxHost, unchanged, into internal types both hosts use:RlpxDialPolicy,RlpxSessionTracker,RlpxListenerandRlpxErrorHandler.SocketRlpxHostaccepts and dials sockets, and owns its connections until their loops end. It is a stoppable service, asRlpxHostis.SocketRlpxConnectionruns three loops. The receive loop fills a pipe from the socket and rents a buffer only once data arrives. The frame loop runs the handshake, then authenticates and decrypts frames, and passes nothing on before the MAC passes. The send loop encodes queued packets in batches.ProcessingThreadCountdedicated threads, with each connection pinned to one, as on DotNetty's executor group. The size limit, Snappy,ReceiveMessageand the error handling run there in order.RlpxHost's watermarks, and the host gets the close signal from it, as the refactor(network)!: give sessions a transport-neutral connection instead of the DotNetty channel #16103 review asked.Differences from DotNetty:
Enqueuereturns 0. On DotNetty, senders that checked writability at the same time all get through.SimulateSendLatencyMs. Writability counts packet bytes only.HandshakeTimeoutscounts only handshakes that run out of time on an open connection. DotNetty also counts connections that ended within 3 seconds for another reason: 971 against 16,443 on mainnet over the same hours.InvalidFrameExceptionandRlpxReadTimeoutExceptioninstead ofCorruptedFrameExceptionandReadTimeoutException. The reasons and log levels are the same.Testing
Nethermind.Network.Test: 3,004 passed, 14 skipped.Benchmark
Compared with DotNetty in the same rounds:
BlockBodiesandByteCodesare 2–6% faster,Receiptsis 5% slower; these aren't paired comparisons.6 paired rounds on the CI runner (AMD EPYC 7713), with two nodes over loopback TCP and Snappy on. Times are medians; Δ is the mean of the per-round changes of the refactored DotNetty host against master, with its 99% interval. The review fixes since then change no socket benchmark significantly (run 1, run 2).
SingleHeaderBlockBodiesReceiptsByteCodesRemarks
New public API:
Network.RlpxTransportsetting and itsRlpxTransportenum;SocketRlpxHost, public becauseNetworkModulein Nethermind.Init registers it. It takes the nameRlpxHostonce the DotNetty host is deleted.NetworkDiagTracerstays enabled after the protocol handler tests that turn it on, and with it on,Session.MarkDisconnectedthrows for an inbound session that hasn't completed its handshake, before the disconnect is reported. That predates this PR; the new host tests turn the tracer off.🤖 AI agent (Claude Code / Opus 5.5) on behalf of @rubo